home *** CD-ROM | disk | FTP | other *** search
/ Champak 140 / (Vol 140) Sep 19 2011.iso / Games / world-wars.swf / scripts / __Packages / classes / Map.as < prev   
Text File  |  2011-09-19  |  29KB  |  850 lines

  1. class classes.Map
  2. {
  3.    var TERRITORY_SIZE_min = 17;
  4.    var TERRITORY_SIZE_max = 28;
  5.    var BORDER_COLOR = 4143636;
  6.    var BORDER_ACTIVE_COLOR = 16777215;
  7.    var BORDER_OVER_COLOR = 13421772;
  8.    var BORDER_SIZE = 2;
  9.    var AV_UNITS_PER_TERRITORY = 3;
  10.    var COLOR_ARR = [11304249,7041575,4541257,10439479,5801101,7419137,8092812,4866561];
  11.    function Map(rmc, gc)
  12.    {
  13.       this.ROOT_MC = rmc;
  14.       this.GAME_CLASS = gc;
  15.       this.HEX = new classes.models.Hex();
  16.       this.cos30 = Math.cos(this.deg2rad(30));
  17.       this.cos60 = Math.cos(this.deg2rad(60));
  18.       this.sin60 = Math.sin(this.deg2rad(60));
  19.    }
  20.    function createMap(players)
  21.    {
  22.       var _loc23_ = 34;
  23.       var _loc24_ = 29;
  24.       var _loc27_ = 30;
  25.       var _loc28_ = 34;
  26.       var _loc26_ = this.random2(_loc28_ - _loc27_) + _loc27_;
  27.       if(this.rubbish_arr.length > 0)
  28.       {
  29.          this.clearAll();
  30.       }
  31.       this.rubbish_arr = new Array();
  32.       this.CHOSEN_TERR_A = this.CHOSEN_TERR_B = undefined;
  33.       this.TERRITORIES_ARR = new Array();
  34.       this.MAP_ARR = new Array();
  35.       this.counter = 0;
  36.       this.drawGrid(_loc23_,_loc24_);
  37.       while(this.TERRITORIES_ARR.length < _loc26_)
  38.       {
  39.          var _loc10_ = undefined;
  40.          var _loc9_ = undefined;
  41.          if(this.TERRITORIES_ARR.length == 0)
  42.          {
  43.             var _loc13_ = Math.round((_loc23_ - 1) / 2);
  44.             var _loc12_ = Math.round((_loc24_ - 1) / 2);
  45.             _loc10_ = Math.round(0.25 * _loc13_ + this.random2(0.5 * _loc13_));
  46.             _loc9_ = Math.round(0.25 * _loc12_ + this.random2(0.5 * _loc12_));
  47.          }
  48.          else
  49.          {
  50.             var _loc8_ = false;
  51.             while(!_loc8_)
  52.             {
  53.                var _loc5_ = this.random2(this.TERRITORIES_ARR.length - 1);
  54.                var _loc6_ = this.TERRITORIES_ARR[_loc5_].arr.length - 1;
  55.                while(_loc6_ >= 0)
  56.                {
  57.                   var _loc3_ = this.freeNeighboursArr2(this.TERRITORIES_ARR[_loc5_].arr[_loc6_]);
  58.                   if(_loc3_.length > 0)
  59.                   {
  60.                      var _loc4_ = this.random2(_loc3_.length - 1);
  61.                      _loc10_ = _loc3_[_loc4_].x;
  62.                      _loc9_ = _loc3_[_loc4_].y;
  63.                      _loc8_ = true;
  64.                   }
  65.                   _loc6_ = _loc6_ - 1;
  66.                }
  67.             }
  68.          }
  69.          var _loc7_ = this.newTerritory(_loc10_,_loc9_);
  70.          if(_loc7_.length > 0)
  71.          {
  72.             var _loc11_ = {status:0,player:0,border:undefined,army:0,unitsMC:undefined,unitsNO:0,arr:_loc7_};
  73.             _loc6_ = 0;
  74.             while(_loc6_ < _loc7_.length)
  75.             {
  76.                _loc7_[_loc6_]._territory = _loc11_;
  77.                _loc6_ = _loc6_ + 1;
  78.             }
  79.             this.TERRITORIES_ARR.push(_loc11_);
  80.          }
  81.       }
  82.       var _loc25_ = _root.ARMY;
  83.       var _loc15_ = new Array();
  84.       _loc6_ = 0;
  85.       while(_loc6_ < players)
  86.       {
  87.          _loc15_.push((_loc6_ + _loc25_ - 1) % 3 + 1);
  88.          _loc6_ = _loc6_ + 1;
  89.       }
  90.       _loc6_ = 0;
  91.       while(_loc6_ < this.TERRITORIES_ARR.length)
  92.       {
  93.          this.makeBorder(this.TERRITORIES_ARR[_loc6_],this.HEX.__get__HEIGHT() / 2);
  94.          this.markTerritory(this.TERRITORIES_ARR[_loc6_],players - _loc6_ % players,0);
  95.          this.TERRITORIES_ARR[_loc6_].army = _loc15_[this.TERRITORIES_ARR[_loc6_].player - 1];
  96.          _loc6_ = _loc6_ + 1;
  97.       }
  98.       this.randomUnits(players);
  99.    }
  100.    function startInterface()
  101.    {
  102.       this.selectA();
  103.    }
  104.    function markTerritory(terrObj, pl, stat)
  105.    {
  106.       var _loc2_ = 0;
  107.       while(_loc2_ < terrObj.arr.length)
  108.       {
  109.          terrObj.arr[_loc2_]._visible = true;
  110.          terrObj.arr[_loc2_].gotoAndStop(pl);
  111.          _loc2_ = _loc2_ + 1;
  112.       }
  113.       this.colorMC(terrObj.border,this.BORDER_COLOR);
  114.       terrObj.status = stat;
  115.       terrObj.player = pl;
  116.    }
  117.    function drawGrid(w, h)
  118.    {
  119.       var _loc11_ = this.HEX.__get__WIDTH();
  120.       var _loc7_ = 0;
  121.       while(_loc7_ < h)
  122.       {
  123.          var _loc8_ = new Array();
  124.          var _loc6_ = 0;
  125.          while(_loc6_ < w)
  126.          {
  127.             var _loc5_ = this.ROOT_MC.attachMovie("HEX","hex_" + _loc6_ + "x" + _loc7_,this.counter++);
  128.             _loc5_._x = _loc6_ * this.HEX.__get__WIDTH() + _loc7_ % 2 * (this.HEX.__get__WIDTH() / 2);
  129.             _loc5_._y = _loc7_ * (this.HEX.__get__HEIGHT() / 2) * 1.5;
  130.             _loc8_.push(_loc5_);
  131.             _loc5_.x = _loc6_;
  132.             _loc5_.y = _loc7_;
  133.             _loc5_._inTerritory = false;
  134.             _loc5_._onBorder = false;
  135.             _loc5_._visible = false;
  136.             this.rubbish_arr.push(_loc5_);
  137.             _loc6_ = _loc6_ + 1;
  138.          }
  139.          this.MAP_ARR.push(_loc8_);
  140.          _loc7_ = _loc7_ + 1;
  141.       }
  142.       var _loc3_ = 0;
  143.       while(_loc3_ < h)
  144.       {
  145.          var _loc2_ = 0;
  146.          while(_loc2_ < w)
  147.          {
  148.             var _loc4_ = this.MAP_ARR[_loc3_][_loc2_];
  149.             _loc4_.L = this.MAP_ARR[_loc3_][_loc2_ - 1];
  150.             _loc4_.R = this.MAP_ARR[_loc3_][_loc2_ + 1];
  151.             if(_loc3_ % 2 == 0)
  152.             {
  153.                _loc4_.TL = this.MAP_ARR[_loc3_ - 1][_loc2_ - 1];
  154.                _loc4_.TR = this.MAP_ARR[_loc3_ - 1][_loc2_];
  155.                _loc4_.BL = this.MAP_ARR[_loc3_ + 1][_loc2_ - 1];
  156.                _loc4_.BR = this.MAP_ARR[_loc3_ + 1][_loc2_];
  157.             }
  158.             else
  159.             {
  160.                _loc4_.TL = this.MAP_ARR[_loc3_ - 1][_loc2_];
  161.                _loc4_.TR = this.MAP_ARR[_loc3_ - 1][_loc2_ + 1];
  162.                _loc4_.BL = this.MAP_ARR[_loc3_ + 1][_loc2_];
  163.                _loc4_.BR = this.MAP_ARR[_loc3_ + 1][_loc2_ + 1];
  164.             }
  165.             _loc2_ = _loc2_ + 1;
  166.          }
  167.          _loc3_ = _loc3_ + 1;
  168.       }
  169.    }
  170.    function newTerritory(x, y)
  171.    {
  172.       var _loc2_ = new Array(this.MAP_ARR[y][x]);
  173.       this.MAP_ARR[y][x]._inTerritory = true;
  174.       var _loc8_ = this.random2(Math.round(this.TERRITORY_SIZE_max - this.TERRITORY_SIZE_min)) + this.TERRITORY_SIZE_min;
  175.       var _loc7_ = false;
  176.       while(_loc2_.length < _loc8_ && !_loc7_)
  177.       {
  178.          var _loc6_ = 0;
  179.          _loc2_ = this.shuffledArray(_loc2_);
  180.          var _loc3_ = 0;
  181.          while(_loc3_ < _loc2_.length)
  182.          {
  183.             var _loc4_ = this.freeNeighboursArr2(_loc2_[_loc3_]);
  184.             if(_loc4_.length > 0)
  185.             {
  186.                var _loc5_ = _loc4_[this.random2(_loc4_.length - 1)];
  187.                _loc2_.push(_loc5_);
  188.                _loc5_._inTerritory = true;
  189.                _loc3_ = _loc2_.length + 10;
  190.             }
  191.             else
  192.             {
  193.                _loc6_ = _loc6_ + 1;
  194.             }
  195.             _loc3_ = _loc3_ + 1;
  196.          }
  197.          if(_loc6_ >= _loc2_.length)
  198.          {
  199.             _loc7_ = true;
  200.          }
  201.       }
  202.       if(_loc7_)
  203.       {
  204.          if(_loc2_.length >= this.TERRITORY_SIZE_min)
  205.          {
  206.             return _loc2_;
  207.          }
  208.          this.burnTerritory(_loc2_);
  209.          return new Array();
  210.       }
  211.       return _loc2_;
  212.    }
  213.    function neighbourTerritoriesNo(terrArr)
  214.    {
  215.       var _loc6_ = new Array();
  216.       var _loc7_ = 0;
  217.       while(_loc7_ < terrArr.length)
  218.       {
  219.          var _loc5_ = terrArr[_loc7_];
  220.          var _loc3_ = [_loc5_.TL,_loc5_.L,_loc5_.TR,_loc5_.BR,_loc5_.R,_loc5_.BL];
  221.          var _loc1_ = 0;
  222.          while(_loc1_ < _loc3_.length)
  223.          {
  224.             if(_loc3_[_loc1_]._territory != _loc5_._territory && _loc3_[_loc1_]._territory != undefined)
  225.             {
  226.                var _loc4_ = false;
  227.                var _loc2_ = 0;
  228.                while(_loc2_ < _loc6_.length && !_loc4_)
  229.                {
  230.                   if(_loc6_[_loc2_] == _loc3_[_loc1_]._territory)
  231.                   {
  232.                      _loc4_ = true;
  233.                   }
  234.                   _loc2_ = _loc2_ + 1;
  235.                }
  236.                if(!_loc4_)
  237.                {
  238.                   _loc6_.push(_loc3_[_loc1_]._territory);
  239.                }
  240.             }
  241.             _loc1_ = _loc1_ + 1;
  242.          }
  243.          _loc7_ = _loc7_ + 1;
  244.       }
  245.       return _loc6_.length;
  246.    }
  247.    function freeNeighboursArr(mc)
  248.    {
  249.       var _loc3_ = new Array();
  250.       var _loc2_ = [mc.TL,mc.L,mc.TR,mc.BR,mc.R,mc.BL];
  251.       var _loc1_ = 0;
  252.       while(_loc1_ < _loc2_.length)
  253.       {
  254.          if(_loc2_[_loc1_] != undefined && _loc2_[_loc1_]._inTerritory == false)
  255.          {
  256.             _loc3_.push(_loc2_[_loc1_]);
  257.          }
  258.          _loc1_ = _loc1_ + 1;
  259.       }
  260.       return _loc3_;
  261.    }
  262.    function freeNeighboursArr2(mc)
  263.    {
  264.       var _loc4_ = new Array();
  265.       var _loc2_ = [mc.TL,mc.L,mc.TR,mc.BR,mc.R,mc.BL,mc.L,mc.R,mc.L,mc.R];
  266.       var _loc1_ = 0;
  267.       while(_loc1_ < _loc2_.length)
  268.       {
  269.          if(_loc2_[_loc1_] != undefined && _loc2_[_loc1_]._inTerritory == false)
  270.          {
  271.             _loc4_.push(_loc2_[_loc1_]);
  272.          }
  273.          _loc1_ = _loc1_ + 1;
  274.       }
  275.       return _loc4_;
  276.    }
  277.    function burnTerritory(terrArr)
  278.    {
  279.       var _loc1_ = 0;
  280.       while(_loc1_ < terrArr.length)
  281.       {
  282.          terrArr[_loc1_]._inTerritory = true;
  283.          _loc1_ = _loc1_ + 1;
  284.       }
  285.    }
  286.    function makeBorder(terrObj, r)
  287.    {
  288.       var _loc7_ = this.BORDER_SIZE;
  289.       var _loc6_ = this.BORDER_COLOR;
  290.       var _loc11_ = new Array();
  291.       var _loc10_ = 0;
  292.       while(_loc10_ < terrObj.arr.length)
  293.       {
  294.          var _loc8_ = terrObj.arr[_loc10_];
  295.          var _loc9_ = [_loc8_.TL,_loc8_.L,_loc8_.TR,_loc8_.BR,_loc8_.R,_loc8_.BL];
  296.          var _loc5_ = 0;
  297.          while(_loc5_ < _loc9_.length)
  298.          {
  299.             if(_loc9_[_loc5_]._territory != terrObj && !_loc8_._onBorder)
  300.             {
  301.                _loc8_._onBorder = true;
  302.                _loc11_.push(_loc8_);
  303.             }
  304.             _loc5_ = _loc5_ + 1;
  305.          }
  306.          _loc10_ = _loc10_ + 1;
  307.       }
  308.       var _loc2_ = this.ROOT_MC.createEmptyMovieClip("border" + this.counter,this.counter++);
  309.       _loc2_._x = _loc11_[0]._x;
  310.       _loc2_._y = _loc11_[0]._y;
  311.       terrObj.border = _loc2_;
  312.       this.rubbish_arr.push(_loc2_);
  313.       _loc10_ = 0;
  314.       while(_loc10_ < _loc11_.length)
  315.       {
  316.          _loc8_ = _loc11_[_loc10_];
  317.          var _loc4_ = _loc8_._x - _loc2_._x;
  318.          var _loc3_ = _loc8_._y - _loc2_._y;
  319.          _loc9_ = [_loc8_.TL,_loc8_.L,_loc8_.TR,_loc8_.BR,_loc8_.R,_loc8_.BL];
  320.          _loc5_ = 0;
  321.          while(_loc5_ < _loc9_.length)
  322.          {
  323.             if(_loc9_[_loc5_]._territory != _loc8_._territory || _loc9_[_loc5_] == undefined)
  324.             {
  325.                switch(_loc5_)
  326.                {
  327.                   case 5:
  328.                      _loc2_.lineStyle(_loc7_,_loc6_,100);
  329.                      _loc2_.moveTo(_loc4_ + this.HEX.__get__BL().x,_loc3_ + this.HEX.__get__BL().y);
  330.                      _loc2_.lineTo(_loc4_ + this.HEX.__get__B().x,_loc3_ + this.HEX.__get__B().y);
  331.                      break;
  332.                   case 1:
  333.                      _loc2_.lineStyle(_loc7_,_loc6_,100);
  334.                      _loc2_.moveTo(_loc4_ + this.HEX.__get__BL().x,_loc3_ + this.HEX.__get__BL().y);
  335.                      _loc2_.lineTo(_loc4_ + this.HEX.__get__TL().x,_loc3_ + this.HEX.__get__TL().y);
  336.                      break;
  337.                   case 3:
  338.                      _loc2_.lineStyle(_loc7_,_loc6_,100);
  339.                      _loc2_.moveTo(_loc4_ + this.HEX.__get__BR().x,_loc3_ + this.HEX.__get__BR().y);
  340.                      _loc2_.lineTo(_loc4_ + this.HEX.__get__B().x,_loc3_ + this.HEX.__get__B().y);
  341.                      break;
  342.                   case 2:
  343.                      _loc2_.lineStyle(_loc7_,_loc6_,100);
  344.                      _loc2_.moveTo(_loc4_ + this.HEX.__get__TR().x,_loc3_ + this.HEX.__get__TR().y);
  345.                      _loc2_.lineTo(_loc4_ + this.HEX.__get__T().x,_loc3_ + this.HEX.__get__T().y);
  346.                      break;
  347.                   case 4:
  348.                      _loc2_.lineStyle(_loc7_,_loc6_,100);
  349.                      _loc2_.moveTo(_loc4_ + this.HEX.__get__TR().x,_loc3_ + this.HEX.__get__TR().y);
  350.                      _loc2_.lineTo(_loc4_ + this.HEX.__get__BR().x,_loc3_ + this.HEX.__get__BR().y);
  351.                      break;
  352.                   case 0:
  353.                      _loc2_.lineStyle(_loc7_,_loc6_,100);
  354.                      _loc2_.moveTo(_loc4_ + this.HEX.__get__TL().x,_loc3_ + this.HEX.__get__TL().y);
  355.                      _loc2_.lineTo(_loc4_ + this.HEX.__get__T().x,_loc3_ + this.HEX.__get__T().y);
  356.                }
  357.             }
  358.             _loc5_ = _loc5_ + 1;
  359.          }
  360.          _loc10_ = _loc10_ + 1;
  361.       }
  362.    }
  363.    function randomUnits(players)
  364.    {
  365.       var _loc12_ = Math.round(this.AV_UNITS_PER_TERRITORY * this.TERRITORIES_ARR.length);
  366.       var _loc9_ = new Array();
  367.       var _loc10_ = new Array();
  368.       var _loc5_ = 0;
  369.       while(_loc5_ < players)
  370.       {
  371.          _loc9_.push(Math.floor(_loc12_ / players));
  372.          _loc5_ = _loc5_ + 1;
  373.       }
  374.       _loc5_ = 0;
  375.       while(_loc5_ < _loc12_ - Math.floor(_loc12_ / players) * players)
  376.       {
  377.          _loc9_[_loc9_.length - 1 - _loc5_] += 1;
  378.          _loc5_ = _loc5_ + 1;
  379.       }
  380.       var _loc15_ = Math.floor(this.TERRITORIES_ARR.length / players);
  381.       var _loc14_ = this.TERRITORIES_ARR.length - players * Math.floor(this.TERRITORIES_ARR.length / players);
  382.       _loc5_ = 0;
  383.       while(_loc5_ < players)
  384.       {
  385.          _loc10_.push(_loc15_);
  386.          _loc5_ = _loc5_ + 1;
  387.       }
  388.       _loc5_ = 0;
  389.       while(_loc5_ < _loc14_)
  390.       {
  391.          _loc10_[_loc10_.length - 1 - _loc5_] += 1;
  392.          _loc5_ = _loc5_ + 1;
  393.       }
  394.       var _loc13_ = new Array();
  395.       var _loc11_ = new Array();
  396.       _loc5_ = 0;
  397.       while(_loc5_ < players)
  398.       {
  399.          var _loc4_ = _loc9_[_loc5_];
  400.          var _loc7_ = _loc10_[_loc5_];
  401.          var _loc8_ = new Array();
  402.          var _loc3_ = 0;
  403.          while(_loc3_ < _loc7_)
  404.          {
  405.             var _loc2_ = 0;
  406.             while(_loc2_ > 8 || _loc2_ < 1)
  407.             {
  408.                _loc2_ = this.random2(Math.floor(_loc4_ / 2) - 1) + 1;
  409.             }
  410.             if(_loc3_ == _loc7_ - 1)
  411.             {
  412.                _loc2_ = _loc4_;
  413.                if(_loc2_ < 1)
  414.                {
  415.                   _loc2_ = 1;
  416.                }
  417.             }
  418.             _loc8_.push(_loc2_);
  419.             _loc4_ -= _loc2_;
  420.             _loc3_ = _loc3_ + 1;
  421.          }
  422.          _loc11_.push(0);
  423.          _loc13_.push(_loc8_);
  424.          _loc5_ = _loc5_ + 1;
  425.       }
  426.       _loc5_ = 0;
  427.       while(_loc5_ < this.TERRITORIES_ARR.length)
  428.       {
  429.          this.TERRITORIES_ARR[_loc5_].unitsNO = _loc13_[this.TERRITORIES_ARR[_loc5_].player - 1][_loc11_[this.TERRITORIES_ARR[_loc5_].player - 1]];
  430.          _loc11_[this.TERRITORIES_ARR[_loc5_].player - 1]++;
  431.          _loc5_ = _loc5_ + 1;
  432.       }
  433.    }
  434.    function territoryA(terr)
  435.    {
  436.       this.CHOSEN_TERR_A = terr;
  437.       this.CHOSEN_TERR_B = undefined;
  438.       this.colorMC(this.CHOSEN_TERR_A.border,this.BORDER_ACTIVE_COLOR);
  439.       this.territoryMaxDepth(this.CHOSEN_TERR_A);
  440.    }
  441.    function territoryB(terr)
  442.    {
  443.       this.CHOSEN_TERR_B = terr;
  444.       this.colorMC(this.CHOSEN_TERR_B.border,this.BORDER_ACTIVE_COLOR);
  445.       var _loc2_ = 0;
  446.       while(_loc2_ < this.TERRITORIES_ARR.length)
  447.       {
  448.          if(this.TERRITORIES_ARR[_loc2_].border.getDepth() == this.CHOSEN_TERR_A.border.getDepth() - 1)
  449.          {
  450.             this.CHOSEN_TERR_B.border.swapDepths(this.TERRITORIES_ARR[_loc2_].border);
  451.             _loc2_ = this.TERRITORIES_ARR.length;
  452.          }
  453.          _loc2_ = _loc2_ + 1;
  454.       }
  455.    }
  456.    function territoryMaxDepth(terrObj)
  457.    {
  458.       var _loc6_ = this.TERRITORIES_ARR[0].border.getDepth();
  459.       var _loc2_ = new Array();
  460.       var _loc5_ = 0;
  461.       while(_loc5_ < this.TERRITORIES_ARR.length)
  462.       {
  463.          if(this.TERRITORIES_ARR[_loc5_].border.getDepth() < _loc6_)
  464.          {
  465.             _loc6_ = this.TERRITORIES_ARR[_loc5_].border.getDepth();
  466.          }
  467.          _loc2_.push(this.TERRITORIES_ARR[_loc5_].border);
  468.          this.TERRITORIES_ARR[_loc5_].border.swapDepths(_loc6_ + 10 + this.TERRITORIES_ARR.length + _loc5_);
  469.          _loc5_ = _loc5_ + 1;
  470.       }
  471.       _loc5_ = 0;
  472.       while(_loc5_ < _loc2_.length)
  473.       {
  474.          var _loc3_ = _loc2_.length - 1;
  475.          while(_loc3_ > _loc5_)
  476.          {
  477.             if(_loc2_[_loc3_ - 1].getDepth() > _loc2_[_loc3_].getDepth())
  478.             {
  479.                var _loc4_ = _loc2_[_loc3_];
  480.                _loc2_[_loc3_] = _loc2_[_loc3_ - 1];
  481.                _loc2_[_loc3_ - 1] = _loc4_;
  482.             }
  483.             _loc3_ = _loc3_ - 1;
  484.          }
  485.          _loc5_ = _loc5_ + 1;
  486.       }
  487.       _loc5_ = 0;
  488.       while(_loc5_ < _loc2_.length)
  489.       {
  490.          if(_loc2_[_loc5_] == terrObj.border)
  491.          {
  492.             _loc2_.splice(_loc5_,1);
  493.          }
  494.          _loc5_ = _loc5_ + 1;
  495.       }
  496.       _loc2_.push(terrObj.border);
  497.       _loc5_ = 0;
  498.       while(_loc5_ < _loc2_.length)
  499.       {
  500.          _loc2_[_loc5_].swapDepths(_loc6_ + _loc5_);
  501.          _loc5_ = _loc5_ + 1;
  502.       }
  503.    }
  504.    function resetTerritory(terr)
  505.    {
  506.       if(this.CHOSEN_TERR_B == terr)
  507.       {
  508.          this.CHOSEN_TERR_B = undefined;
  509.       }
  510.       if(this.CHOSEN_TERR_A == terr)
  511.       {
  512.          this.CHOSEN_TERR_A = undefined;
  513.       }
  514.       this.markTerritory(terr,terr.player,0);
  515.    }
  516.    function unMarkIfMarked()
  517.    {
  518.       this.colorMC(this.CHOSEN_TERR_A.border,this.BORDER_COLOR);
  519.       this.deselectAll();
  520.    }
  521.    function selectA()
  522.    {
  523.       if(!this.GAME_CLASS.isGameFinished())
  524.       {
  525.          var root = this;
  526.          var _loc4_ = 0;
  527.          while(_loc4_ < this.TERRITORIES_ARR.length)
  528.          {
  529.             var _loc6_ = false;
  530.             var _loc7_ = this.neighboursAreasArr(this.TERRITORIES_ARR[_loc4_].arr);
  531.             var _loc5_ = 0;
  532.             while(_loc5_ < _loc7_.length && !_loc6_)
  533.             {
  534.                if(_loc7_[_loc5_].player != this.TERRITORIES_ARR[_loc4_].player)
  535.                {
  536.                   _loc6_ = true;
  537.                }
  538.                _loc5_ = _loc5_ + 1;
  539.             }
  540.             if(_loc6_)
  541.             {
  542.                _loc5_ = 0;
  543.                while(_loc5_ < this.TERRITORIES_ARR[_loc4_].arr.length)
  544.                {
  545.                   var _loc3_ = this.TERRITORIES_ARR[_loc4_].arr[_loc5_];
  546.                   if(_loc3_._territory.player == 1 && _loc3_._territory.unitsNO > 1)
  547.                   {
  548.                      _loc3_.onRelease = function()
  549.                      {
  550.                         _global.SOUNDS.playSound("Click- g┼éo┼¢niejszy.wav");
  551.                         if(this._territory == root.CHOSEN_TERR_A)
  552.                         {
  553.                            root.colorMC(root.CHOSEN_TERR_A.border,root.BORDER_COLOR);
  554.                            root.lightOffTerritory(root.CHOSEN_TERR_A);
  555.                            root.deselectB();
  556.                            root.CHOSEN_TERR_A = undefined;
  557.                         }
  558.                         else
  559.                         {
  560.                            root.colorMC(root.CHOSEN_TERR_A.border,root.BORDER_COLOR);
  561.                            root.lightOffTerritory(root.CHOSEN_TERR_A);
  562.                            root.deselectB();
  563.                            root.territoryA(this._territory);
  564.                            root.lightOffTerritory(this._territory);
  565.                            root.selectB();
  566.                         }
  567.                      };
  568.                      _loc3_.onRollOver = function()
  569.                      {
  570.                         if(this._territory != root.CHOSEN_TERR_A)
  571.                         {
  572.                            root.lightOnTerritory(this._territory);
  573.                         }
  574.                      };
  575.                      _loc3_.onRollOut = _loc3_.onReleaseOutside = function()
  576.                      {
  577.                         if(this._territory != root.CHOSEN_TERR_A)
  578.                         {
  579.                            root.lightOffTerritory(this._territory);
  580.                         }
  581.                      };
  582.                   }
  583.                   _loc5_ = _loc5_ + 1;
  584.                }
  585.             }
  586.             _loc4_ = _loc4_ + 1;
  587.          }
  588.       }
  589.    }
  590.    function selectB()
  591.    {
  592.       this.findAneighbours();
  593.       var root = this;
  594.       var _loc4_ = 0;
  595.       while(_loc4_ < this.TERR_A_NArr.length)
  596.       {
  597.          if(this.TERR_A_NArr[_loc4_].player != 1)
  598.          {
  599.             var _loc3_ = 0;
  600.             while(_loc3_ < this.TERR_A_NArr[_loc4_].arr.length)
  601.             {
  602.                var _loc5_ = this.TERR_A_NArr[_loc4_].arr[_loc3_];
  603.                _loc5_.onRelease = function()
  604.                {
  605.                   _global.SOUNDS.playSound("Click- g┼éo┼¢niejszy.wav");
  606.                   root.territoryB(this._territory);
  607.                   root.fightAB();
  608.                   root.deselectAll();
  609.                };
  610.                _loc3_ = _loc3_ + 1;
  611.             }
  612.          }
  613.          _loc4_ = _loc4_ + 1;
  614.       }
  615.    }
  616.    function deselectB()
  617.    {
  618.       this.findAneighbours();
  619.       var _loc5_ = this;
  620.       var _loc3_ = 0;
  621.       while(_loc3_ < this.TERR_A_NArr.length)
  622.       {
  623.          if(this.TERR_A_NArr[_loc3_].player != 1)
  624.          {
  625.             var _loc2_ = 0;
  626.             while(_loc2_ < this.TERR_A_NArr[_loc3_].arr.length)
  627.             {
  628.                var _loc4_ = this.TERR_A_NArr[_loc3_].arr[_loc2_];
  629.                delete _loc4_.onRelease;
  630.                _loc2_ = _loc2_ + 1;
  631.             }
  632.          }
  633.          _loc3_ = _loc3_ + 1;
  634.       }
  635.    }
  636.    function deselectA()
  637.    {
  638.       var _loc5_ = this;
  639.       var _loc4_ = 0;
  640.       while(_loc4_ < this.TERR_A_NArr.length)
  641.       {
  642.          if(this.TERR_A_NArr[_loc4_].player == 1)
  643.          {
  644.             var _loc3_ = 0;
  645.             while(_loc3_ < this.TERR_A_NArr[_loc4_].arr.length)
  646.             {
  647.                var _loc2_ = this.TERR_A_NArr[_loc4_].arr[_loc3_];
  648.                delete _loc2_.onRollOut;
  649.                delete _loc2_.onReleaseOutside;
  650.                delete _loc2_.onRollOver;
  651.                delete _loc2_.onRelease;
  652.                _loc3_ = _loc3_ + 1;
  653.             }
  654.          }
  655.          _loc4_ = _loc4_ + 1;
  656.       }
  657.    }
  658.    function deselectAll()
  659.    {
  660.       var _loc3_ = 0;
  661.       while(_loc3_ < this.TERRITORIES_ARR.length)
  662.       {
  663.          var _loc2_ = 0;
  664.          while(_loc2_ < this.TERRITORIES_ARR[_loc3_].arr.length)
  665.          {
  666.             delete this.TERRITORIES_ARR[_loc3_].arr[_loc2_].onRollOver;
  667.             delete this.TERRITORIES_ARR[_loc3_].arr[_loc2_].onRollOut;
  668.             delete this.TERRITORIES_ARR[_loc3_].arr[_loc2_].onReleaseOutside;
  669.             delete this.TERRITORIES_ARR[_loc3_].arr[_loc2_].onRelease;
  670.             _loc2_ = _loc2_ + 1;
  671.          }
  672.          _loc3_ = _loc3_ + 1;
  673.       }
  674.    }
  675.    function findAneighbours()
  676.    {
  677.       this.TERR_A_NArr = new Array();
  678.       var _loc8_ = this.CHOSEN_TERR_A.arr;
  679.       var _loc7_ = 0;
  680.       while(_loc7_ < _loc8_.length)
  681.       {
  682.          var _loc6_ = _loc8_[_loc7_];
  683.          var _loc4_ = [_loc6_.TL,_loc6_.L,_loc6_.TR,_loc6_.BR,_loc6_.R,_loc6_.BL];
  684.          var _loc2_ = 0;
  685.          while(_loc2_ < _loc4_.length)
  686.          {
  687.             if(_loc4_[_loc2_]._territory != _loc6_._territory && _loc4_[_loc2_]._territory != undefined)
  688.             {
  689.                var _loc5_ = false;
  690.                var _loc3_ = 0;
  691.                while(_loc3_ < this.TERR_A_NArr.length && !_loc5_)
  692.                {
  693.                   if(this.TERR_A_NArr[_loc3_] == _loc4_[_loc2_]._territory)
  694.                   {
  695.                      _loc5_ = true;
  696.                   }
  697.                   _loc3_ = _loc3_ + 1;
  698.                }
  699.                if(!_loc5_)
  700.                {
  701.                   this.TERR_A_NArr.push(_loc4_[_loc2_]._territory);
  702.                }
  703.             }
  704.             _loc2_ = _loc2_ + 1;
  705.          }
  706.          _loc7_ = _loc7_ + 1;
  707.       }
  708.    }
  709.    function neighboursAreasArr(terrArr)
  710.    {
  711.       var _loc6_ = new Array();
  712.       var _loc7_ = 0;
  713.       while(_loc7_ < terrArr.length)
  714.       {
  715.          var _loc5_ = terrArr[_loc7_];
  716.          var _loc3_ = [_loc5_.TL,_loc5_.L,_loc5_.TR,_loc5_.BR,_loc5_.R,_loc5_.BL];
  717.          var _loc1_ = 0;
  718.          while(_loc1_ < _loc3_.length)
  719.          {
  720.             if(_loc3_[_loc1_]._territory != _loc5_._territory && _loc3_[_loc1_]._territory != undefined)
  721.             {
  722.                var _loc4_ = false;
  723.                var _loc2_ = 0;
  724.                while(_loc2_ < _loc6_.length && !_loc4_)
  725.                {
  726.                   if(_loc6_[_loc2_] == _loc3_[_loc1_]._territory)
  727.                   {
  728.                      _loc4_ = true;
  729.                   }
  730.                   _loc2_ = _loc2_ + 1;
  731.                }
  732.                if(!_loc4_)
  733.                {
  734.                   _loc6_.push(_loc3_[_loc1_]._territory);
  735.                }
  736.             }
  737.             _loc1_ = _loc1_ + 1;
  738.          }
  739.          _loc7_ = _loc7_ + 1;
  740.       }
  741.       return _loc6_;
  742.    }
  743.    function lightOnTerritory(terrObj)
  744.    {
  745.       var _loc1_ = 0;
  746.       while(_loc1_ < terrObj.arr.length)
  747.       {
  748.          terrObj.arr[_loc1_]._alpha = 70;
  749.          _loc1_ = _loc1_ + 1;
  750.       }
  751.    }
  752.    function lightOffTerritory(terrObj)
  753.    {
  754.       var _loc1_ = 0;
  755.       while(_loc1_ < terrObj.arr.length)
  756.       {
  757.          terrObj.arr[_loc1_]._alpha = 100;
  758.          _loc1_ = _loc1_ + 1;
  759.       }
  760.    }
  761.    function fightAB()
  762.    {
  763.       this.GAME_CLASS.FIGHTBOX.resetWinner();
  764.       this.GAME_CLASS.FIGHTBOX.fight(this.CHOSEN_TERR_A,this.CHOSEN_TERR_B);
  765.    }
  766.    function winnerFound()
  767.    {
  768.       if(this.GAME_CLASS.FIGHTBOX.WINNER == this.CHOSEN_TERR_A)
  769.       {
  770.          this.winA();
  771.          if(this.GAME_CLASS.PLAYER_MOVE == 1 && !this.GAME_CLASS.isGameFinished())
  772.          {
  773.             _global.setTimeout(mx.utils.Delegate.create(this.GAME_CLASS,this.GAME_CLASS.showBiggestArea),300);
  774.          }
  775.       }
  776.       if(this.GAME_CLASS.FIGHTBOX.WINNER == this.CHOSEN_TERR_B)
  777.       {
  778.          this.winB();
  779.       }
  780.       var _loc4_ = new Array();
  781.       var _loc3_ = 1;
  782.       while(_loc3_ <= this.GAME_CLASS.PLAYERS_NO)
  783.       {
  784.          _loc4_.push(this.GAME_CLASS.unitsToAdd(_loc3_));
  785.          _loc3_ = _loc3_ + 1;
  786.       }
  787.       this.GAME_CLASS.UNITS_LIST.refreshList(_loc4_,this.TERRITORIES_ARR);
  788.    }
  789.    function winA()
  790.    {
  791.       this.markTerritory(this.CHOSEN_TERR_B,this.CHOSEN_TERR_A.player,0);
  792.       this.CHOSEN_TERR_B.unitsNO = this.CHOSEN_TERR_A.unitsNO - 1;
  793.       this.CHOSEN_TERR_A.unitsNO = 1;
  794.       this.CHOSEN_TERR_B.army = this.CHOSEN_TERR_A.army;
  795.       this.CHOSEN_TERR_A.unitsMC.setUnit(this.CHOSEN_TERR_A.army,this.CHOSEN_TERR_A.unitsNO,this.CHOSEN_TERR_A.player);
  796.       this.CHOSEN_TERR_B.unitsMC.setUnit(this.CHOSEN_TERR_A.army,this.CHOSEN_TERR_B.unitsNO,this.CHOSEN_TERR_B.player);
  797.       this.resetTerritory(this.CHOSEN_TERR_A);
  798.       this.resetTerritory(this.CHOSEN_TERR_B);
  799.       this.deselectAll();
  800.    }
  801.    function winB()
  802.    {
  803.       this.CHOSEN_TERR_A.unitsNO = 1;
  804.       this.CHOSEN_TERR_A.unitsMC.setUnit(this.CHOSEN_TERR_A.army,this.CHOSEN_TERR_A.unitsNO,this.CHOSEN_TERR_A.player);
  805.       this.resetTerritory(this.CHOSEN_TERR_A);
  806.       this.resetTerritory(this.CHOSEN_TERR_B);
  807.       this.deselectAll();
  808.    }
  809.    function colorMC(mc, cl)
  810.    {
  811.       var _loc1_ = new Color(mc);
  812.       _loc1_.setRGB(cl);
  813.    }
  814.    function rad2deg(rad)
  815.    {
  816.       return rad * 180 / 3.141592653589793;
  817.    }
  818.    function deg2rad(deg)
  819.    {
  820.       return deg * 3.141592653589793 / 180;
  821.    }
  822.    function random2(z)
  823.    {
  824.       return Math.round(Math.random() * z);
  825.    }
  826.    function shuffledArray(arr)
  827.    {
  828.       var _loc5_ = 0;
  829.       while(_loc5_ < 30)
  830.       {
  831.          var _loc4_ = this.random2(arr.length - 1);
  832.          var _loc3_ = this.random2(arr.length - 1);
  833.          var _loc6_ = arr[_loc4_];
  834.          arr[_loc4_] = arr[_loc3_];
  835.          arr[_loc3_] = _loc6_;
  836.          _loc5_ = _loc5_ + 1;
  837.       }
  838.       return arr;
  839.    }
  840.    function clearAll()
  841.    {
  842.       var _loc2_ = 0;
  843.       while(_loc2_ < this.rubbish_arr.length)
  844.       {
  845.          this.rubbish_arr[_loc2_].removeMovieClip();
  846.          _loc2_ = _loc2_ + 1;
  847.       }
  848.    }
  849. }
  850.